#include"BinaryTree.h"
TreeNode* BuyNode(BTDataType x)
{
	TreeNode* newnode = (TreeNode*)malloc(sizeof(TreeNode));
	if (newnode == NULL)
	{
		printf("malloc fail\n");
		exit(-1);
	}
	else
	{
		newnode->val = x;
		newnode->left = NULL;
		newnode->right = NULL;
	}
	return newnode;
}

TreeNode* BuyTree()
{
	//构建一颗二叉树
    //1.创建结点
	TreeNode* nodeA = BuyNode('A');
	TreeNode* nodeB = BuyNode('B');
	TreeNode* nodeC = BuyNode('C');
	TreeNode* nodeD = BuyNode('D');
	TreeNode* nodeE = BuyNode('E');
	TreeNode* nodeF = BuyNode('F');

	//2.链接
	nodeA->left = nodeB;
	nodeA->right = nodeC;

	nodeB->left = nodeD;

	nodeC->left = nodeE;
	nodeC->right = nodeF;

	return nodeA;

//        A
//	   B        C
//	D   NULL  E  F
}
int main()
{
	TreeNode* root = BuyTree();
	PreOrder(root); //测试前序
	printf("\n");
	InOrder(root);//测试中序
	printf("\n");

	PostOrder(root);//测试后序
	printf("\n");
	printf("TreeSize = %d\n", BinaryTreeSize(root));
	printf("TreeLeafSize = %d\n", BinaryTreeLeafSize(root));

	printf("以A为根结点,第%d层结点个数为:%d\n", 2, BinaryTreeLevelSize(root, 2));
	printf("以A为根结点,第%d层结点个数为:%d\n", 3, BinaryTreeLevelSize(root, 3));
	printf("二叉树的高度为：%d\n",BinaryTreeDepth(root));
    LevelOrder(root);//测试层序遍历
	
	
    printf("%d\n",BinaryTreeComplete(root));
    printf("%p\n",BinaryTreeFind(root,'F'));

    BinaryTreeDestory(root);//注意：记得在最后销毁二叉树！！！！
	return 0;
}
